package com.rivercloud.dao.Impl;

import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.rivercloud.dao.MergeDao;
import com.rivercloud.entity.Merge;
import com.rivercloud.entity.User;

public class MergeDaoImpl implements MergeDao {
	 static SqlSessionFactory sqlSessionFactory = null;
	 static{
		 SqlSessionFactoryBuilder sessionFactoryBuilder = new SqlSessionFactoryBuilder();
		 InputStream inputStream =null;
		 
		 try {
			inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		sqlSessionFactory = sessionFactoryBuilder.build(inputStream);
	 }   




	@Override
	public void mergeBoxCol(Merge merge) {
		SqlSession session = sqlSessionFactory.openSession();
		session.insert("mergeBoxCol",merge);
		session.commit();
		session.close();
		
		
	}




	@Override
	public List<Merge> findMergeByTableId(Integer tableId) {
		SqlSession session = sqlSessionFactory.openSession();
		List<Merge> list = session.selectList("findMergeByTableId", tableId);
		
		session.close();
		return list;
	}




	@Override
	public Merge findMergeByInfo(Merge merge) {
		SqlSession session = sqlSessionFactory.openSession();
		Merge existMerge = session.selectOne("findMergeByInfo", merge);
		
		session.close();
		return existMerge;
	}




	@Override
	public void updateMergeBoxCol(Merge merge) {
		SqlSession session = sqlSessionFactory.openSession();
		session.update("updateMergeBoxCol", merge);
		session.commit();
		session.close();
	}




	@Override
	public void addMergeBoxRow(Merge merge) {
		SqlSession session = sqlSessionFactory.openSession();
		session.insert("addMergeBoxRow",merge);
		session.commit();
		session.close();
	}




	@Override
	public void updateMergeBoxRow(Merge merge) {
		SqlSession session = sqlSessionFactory.openSession();
		session.update("updateMergeBoxRow", merge);
		session.commit();
		session.close();
		
	}




	@Override
	public void deleteMergeCol(Merge merge) {
		SqlSession session = sqlSessionFactory.openSession();
		session.delete("deleteMergeCol", merge);
		session.commit();
		session.close();
		
	}




	@Override
	public void deleteMergeColByTableId(Integer tableId) {
		SqlSession session = sqlSessionFactory.openSession();
		session.delete("deleteMergeColByTableId", tableId);
		session.commit();
		session.close();
	}
}
